home *** CD-ROM | disk | FTP | other *** search
- ' this is a custom HTTP Module
- ' it is enabled by the following lines in Web.Config
-
- '<httpModules>
- ' <add name="ErrorLogger" type="AspnetApplications.ErrorLoggerModule,AspnetApplications" />
- '</httpModules>
-
- Public Class ErrorLoggerModule
- Implements IHttpModule
-
- ' The Application object.
- Dim WithEvents Application As HttpApplication
-
- ' This is where we store all error messages since the application was started
- Public Shared ErrorMessages As New ArrayList()
-
- ' this method is called by ASP.NET when the application starts.
-
- Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
- ' Store the Application object in a local variable.
- Application = context
- End Sub
-
- ' this method is called by ASP.NET when the application is about to end
-
- Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
- ' Nothing important to do in this case.
- Application = Nothing
- End Sub
-
- ' the current HTTP module traps the Application_Error event
- ' it prepares a detailed report of the error and appends it to the
- ' ErrorMessages arraylist object.
-
- Private Sub Application_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Application.Error
- ' prepare details about the error.
- Dim msg As String
- msg &= "<b>An exception has occurred at</b> " & Now.ToString & "<BR />"
- msg &= "<b>URL</b> = " & Application.Request.Path & "<BR />"
- msg &= "<b>QueryString</b> = " & Application.Request.QueryString.ToString & "<BR /><BR />"
-
- ' Append details about the error, but convert CR-LF pairs.
- msg &= Application.Server.GetLastError.ToString.Replace(ControlChars.CrLf, "<BR />")
-
- ' prepend to the collection of error messages
- SyncLock ErrorMessages.SyncRoot
- ErrorMessages.Insert(0, msg)
- End SyncLock
-
- End Sub
-
- End Class
-